//
//  IWSearchBar.m
//
//
//  Created by apple on .
//  Copyright (c) 2015年 itcast. All rights reserved.
//

#import "TTSearchBar.h"

@implementation TTSearchBar

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 1.设置背景图片
        self.background = [UIImage resizableImageWithName:@"searchbar_textfield_background"];
        
        // 2.设置文本垂直居中
        self.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
        
        // 3.设置清除按钮
        self.clearButtonMode = UITextFieldViewModeWhileEditing;
        
        // 4.添加放大镜
        // 4.1创建UIImageView的同时初始化image, 那么UIImageView的frame就是image的size
        UIImageView *iv = [[UIImageView alloc] initWithImage:[UIImage imageWithName:@"searchbar_textfield_search_icon"]];
        // 4.2设置放大镜为leftview
        self.leftView = iv;
        self.leftViewMode = UITextFieldViewModeAlways;
        iv.width = 40;
        iv.contentMode = UIViewContentModeCenter;
        
        // 5.设置默认提示信息
        self.placeholder = @"亲~请输入要搜索的内容";
        self.font = [UIFont systemFontOfSize:13];

    }
    return self;
}


@end
